using System;
using Slaks.DocumentSerialization.Dictionary;
using Slaks.DocumentSerialization.Document;

namespace Slaks.Graphs.GraphBuilder.SchenkerDictionary
{
	/// <summary>
	/// Summary description for NSimpleDistanceRepresentationSlaks.
	/// </summary>
	public class NSimpleDistanceDictionaryRepresentationSchenker : SchenkerDictionaryBuilder, IDictionaryRepresentation
	{
		#region IDictionaryRepresentation Members

		public Graph Build(Document document, DictionaryMap dictionaryMap)
		{
			throw new NotImplementedException("NSimpleDistanceDictionaryRepresentationSlaks does not implement this method");
		}

		public Graph Build(Document document, int nParameter, DictionaryMap dictionaryMap)
		{
			string documentName = document.FileName;
			int index = documentName.LastIndexOfAny(new char[] {'\\', '/'});
			if (index >= 0 && (index + 1 < documentName.Length)) documentName = documentName.Substring(index + 1);

			Graph graph = new Graph(documentName);

			Vertex vertex;
			string sectionType;

			int nDistanceCount;
			//iterate through nodes
			foreach (Node node in document.Nodes)
			{
				//check if the vertex is in the list of frequent nodes from dictionary
				if (dictionaryMap.Contains(node.Id) == false) continue;
				vertex = graph.CreateAddVertex(node.Id);

				//iterate through sections
				foreach (Section section in node.Sections)
				{
					sectionType = section.GetSectionTypeString();

					vertex.Frequency = section.TermFrequency;
					Section.SectionType sectionTp = Section.GetSectionTypeByString(sectionType);

					nDistanceCount = 1;
					//iterate through sentences
					foreach (Sentence sentence in section.Sentences)
					{
						AddRelations(document, graph, dictionaryMap, vertex, nParameter, nDistanceCount, sentence, sectionTp, BuilderType.NSimpleDistanceDictionaryRepresentationSchenker);
					}
				}
			}
			return graph;
		}
        protected override string GetBuilderName()
        {
            return "Schenker's N-Simple Distance By Dictionary Representation";
        }
        protected override string GetBuilderDescription()
        {
            return "Add edges between vertexes up to a the n-th fartherest vertex, but doesn't label them. Only most frequent terms are used.";
        }
		#endregion
	}
}